package com.southwind.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.southwind.common.BikePageModel;
import com.southwind.common.Cache;
import com.southwind.common.DataGridView;
import com.southwind.common.ViolationPageModel;
import com.southwind.entity.Bike;
import com.southwind.entity.User;
import com.southwind.entity.Violation;
import com.southwind.service.ViolationService;
import com.southwind.vo.BikeVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-04-29
 */
@RestController
@RequestMapping("/violation")
public class ViolationController {

    @Autowired
    private ViolationService violationService;

    @GetMapping("/list")
    public DataGridView list(ViolationPageModel violationPageModel){
        User user = (User) Cache.map.get("user");
        Page<Violation> page = new Page<>(violationPageModel.getPage(), violationPageModel.getLimit());
        QueryWrapper<Violation> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(violationPageModel.getCause()), "cause", violationPageModel.getCause())
                    .eq("uid", user.getId());
        Page<Violation> resultPage = this.violationService.page(page,queryWrapper);
        DataGridView dataGridView = new DataGridView(resultPage.getTotal(), resultPage.getRecords());
        return dataGridView;
    }

}

